package wap._2015.game._1;

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// Inputs
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] map = new int[n + 1][m + 1];
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				map[i][j] = in.nextInt();
		in.close();
		
		// Calculate
		int[][] sum = new int[n + 1][m + 1];
		int[][] countBlocked = new int[n + 1][m + 1];
		for (int i = 1; i <= m; i++)
			for (int j = 1; j <= n; j++) {
				countBlocked[j][i] = (map[j][i] < 0)? countBlocked[j - 1][i] + 1 : countBlocked[j - 1][i];
				sum[j][i] = sum[j - 1][i] + map[j][i];
			}
		int[] nowColumn = new int[n + 1];
		int[][] f = new int[n + 1][n + 1];
		for (int i = 1; i <= m; i++) {
			for (int x = 1; x <= n; x++) {
				// When it's impossible to get in from X
				if (nowColumn[x] < 0) {
					for (int y = 1; y <= n; y++)
						f[x][y] = -1;
					continue;
				}
				
				// When get out through Y where Y < X
				for (int y = 1; y < x; y++) {
					int temp = -1;
					if (countBlocked[x][i] - countBlocked[y - 1][i] == 0)
						temp = Math.max(temp, nowColumn[x] + sum[x][i] - sum[y - 1][i]);
					if (countBlocked[n][i] - countBlocked[x - 1][i] == 0 && countBlocked[y][i] == 0)
						temp = Math.max(temp, sum[y][i]);
					f[x][y] = temp;
				}
				
				// When get out through frome same cell
				f[x][x] = (countBlocked[x][i] - countBlocked[x - 1][i] == 0)? nowColumn[x] + map[x][i]: -1;
				
				// When get out through Y where Y > x
				for (int y = x + 1; y <= n; y++) {
					int temp = -1;
					if (countBlocked[y][i] - countBlocked[x - 1][i] == 0)
						temp = Math.max(temp, nowColumn[x] + sum[y][i] - sum[x - 1][i]);
					if (countBlocked[n][i] - countBlocked[y - 1][i] == 0 && countBlocked[x][i] == 0)
						temp = Math.max(temp, sum[n][i] - sum[y - 1][i]);
					f[x][y] = temp;
				}
			}
			
			for (int x = 1; x <= n; x++) {
				int temp = -1;
				for (int y = 1; y <= n; y++)
					temp = Math.max(temp, f[y][x]);
				nowColumn[x] = temp;
			}
		}
		int ans = -1;
		for (int i = 1; i <= n; i++)
			ans = Math.max(ans, nowColumn[i]);
		
		// Outputs
		System.out.println(ans);
	}

}

//TEST 1 : 23
//4 4
//-1 4 5 1
//2 -1 2 4
//3 3 -1 3
//4 2 1 2

//TEST 2 : 16
//4 4
//-1 4 5 1
//2 -1 2 4
//3 3 -1 -1
//4 2 1 2

//TEST 3 : -1
//4 5
//-1 -1 -1 -1 -1
//5 -1 2 3 1
//2 4 -1 7 1
//2 0 9 -1 9

//TEST 4 : 22
//4 5
//-1 0 0 2 1
//5 -1 2 3 1
//2 4 -1 7 1
//2 0 9 -1 9

//TEST 5 : -1
//4 5
//-1 0 -1 2 1
//5 -1 2 3 1
//2 4 -1 7 1
//2 0 9 -1 9

//TEST 6 : 33
//4 10
//-1  0  1  0  1  9  1  7 -1  1 
// 5 -1  2  3  1  2  0 -1  1  9
// 2  4 -1  7  1  0 -1  1  9  7
// 2  0  9 -1  9 -1  1  3  0  2